﻿<%@ WebHandler Language="C#" Class="wxMiniProgramLogin" %>
using Models;
using System;
using System.Web;
using Newtonsoft.Json;
using System.Linq;
using System.Web.Configuration;
using Newtonsoft.Json.Linq;
using System.IO;
using System.Net;


public class wxMiniProgramLogin : IHttpHandler {

    public void ProcessRequest (HttpContext context)
    {
        context.Response.ContentType = "text/plain";

        var xxx=HttpContext.Current.Request.Form["paramJson"];

        string openid = context.Request.Headers["X-ACCESS-USER"];//Header中的token

        // JObject jo = (JObject)JsonConvert.DeserializeObject(xxx);
        // var openid=jo["onlyId"].ToString();
        //var nickName=jo["nickName"].ToString();
        //var birthday=jo["birthday"].ToString();
        //var sex=jo["relationship"].ToString();

        var nickName=HttpContext.Current.Request.Form["nickname"];
        var avatar=HttpContext.Current.Request.Form["avatar"];
        var city=HttpContext.Current.Request.Form["city"];
        var gender=HttpContext.Current.Request.Form["gender"];

        //nickname: 李锋
        //avatar: https://thirdwx.qlogo.cn/mmopen/vi_32/ajNVdqHZLLDDr5p6QEMl8z0xEw22xcq5JTsjiaic9dib2T5TC0mnINraKtFFgTAOzFBgYpA3NlVjfgADCqibR0nDicw/132
        //gender: 1
        //city: 昆明

        using (Entities db = new Entities())
        {
            var wxuser = db.User.FirstOrDefault(p => p.UOpenID == openid);
            wxuser.UNickName=nickName;
            wxuser.UHeadImg=avatar;
            //wxuser.UProvince=city;
            //wxuser. = gender;
            wxuser.isMember=1;
            db.SaveChanges();

        };


        var  code = 1;
        var  msg = "zhuc";
        var  time = DateTime.Now;

        context.Response.Write(JsonConvert.SerializeObject(new {code,msg,time}));

        HttpContext.Current.Response.End();
        //context.Response.Write("Hello World");


    }


    public bool IsReusable {
        get {
            return false;
        }
    }

}